package app.texas.com.devilfishhouse.View.login;

import android.content.Intent;
import android.graphics.Paint;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;


import com.universal_library.weight.MyTitleBar;

import app.texas.com.devilfishhouse.Base.BasePresenter;
import app.texas.com.devilfishhouse.Base.BaseView;
import app.texas.com.devilfishhouse.Beans.LoginBean;
import app.texas.com.devilfishhouse.R;
import app.texas.com.devilfishhouse.View.regitst.RegistView;
import butterknife.BindView;
import butterknife.OnClick;


/**
 * Created by lenovo on 2018/5/21.
 */


public class LoginView extends BaseView implements View.OnClickListener {
    private LoginPersenter loginPersenter;
    @BindView(R.id.bt_login)
    Button button;

    @BindView(R.id.et_phone)
    EditText et_phone;

    @BindView(R.id.et_pwd)
    EditText et_pwd;

    @BindView(R.id.tv_forget)
    TextView tv_forget;

    @BindView(R.id.tv_regist)
    TextView tv_regitst;

    //处理中
    private final static int SUCCESS = 0;
    private final static int ERROR = -1;
    private final static int LOADING = 1;
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case SUCCESS:
                    Toast.makeText(LoginView.this, (String) msg.obj, Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    };

    @Override
    protected void initView() {
        super.initView();
        tv_forget.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        tv_regitst.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        initTitle();
    }

    @Override
    protected void initData() {

    }


    @Override
    protected int getLayoutId() {
        return R.layout.activity_login_view;
    }

    @Override
    protected BasePresenter getPresenter() {
        loginPersenter = new LoginPersenter(this);
        return loginPersenter;
    }

    @OnClick({R.id.bt_login, R.id.tv_regist, R.id.tv_forget})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_login:
                loginPersenter.setLoginParams(et_phone.getText().toString(), et_pwd.getText().toString());
                break;
            case R.id.tv_forget:
                break;
            case R.id.tv_regist:
                startActivity(new Intent(this, RegistView.class));
                break;
        }
    }

    //传递回来的数据
    @Override
    public void setData(Object data) {
        super.setData(data);
        LoginBean loginBean = (LoginBean) data;
        Message msg = Message.obtain();
        msg.what = SUCCESS;
//        msg.obj = loginBean.getMsg();
        handler.sendMessage(msg);
    }

    @Override
    protected int getTitleRes() {
        return R.string.login;
    }
}
